﻿using System;
using System.ComponentModel;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;

namespace DotNet.Phone8.MvvmLight.Extensions
{
    public interface INavigateService
    {
        PhoneApplicationFrame RootFrame { get; }

        /// <summary>
        /// 导航到目标页
        /// </summary>
        /// <param name="desUri">导航目标页</param>
        /// <param name="uriKind">路径类型</param>
        /// <returns>是否成功</returns>
        bool Navigate(string desUri, UriKind uriKind);

        /// <summary>
        /// 导航到目标页
        /// </summary>
        /// <param name="source">带参数的Uri</param>
        /// <returns>是否成功</returns>
        bool Navigate(NavigationUri source);

        /// <summary>
        /// 是否从墓碑机制恢复
        /// </summary>
        bool RecoveredFromTombstoning { get; set; }

        /// <summary>
        /// 按回退键时发生
        /// </summary>
        event EventHandler<CancelEventArgs> BackKeyPress;

        /// <summary>
        /// 当请求新的导航时发生
        /// </summary>
        event NavigatingCancelEventHandler Navigating;

        /// <summary>
        /// 导航到页面时发生
        /// </summary>
        event NavigatedEventHandler Navigated;

        /// <summary>
        /// 导航参数
        /// </summary>
        NavigationUri NavigationUri { get; }

        /// <summary>
        /// 注册View和ViewModel的关系，建议写在InitializePhoneApplication事件中的最后一行代码
        /// </summary>
        /// <typeparam name="TView"></typeparam>
        /// <typeparam name="TViewModel"></typeparam>
        void Register<TView, TViewModel>()
            where TView : class
            where TViewModel : class;

        /// <summary>
        /// 根据ViewModel获取对应的View类型
        /// </summary>
        /// <typeparam name="TViewModel"></typeparam>
        /// <returns></returns>
        Type GetViewType<TViewModel>()
            where TViewModel : class;

        /// <summary>
        /// 根据ViewModel的类型获取注册的View类型
        /// </summary>
        /// <param name="tViewModel"></param>
        /// <returns></returns>
        Type GetViewType(Type tViewModel);

        /// <summary>
        /// 删除最后一个导航的Entry
        /// </summary>
        void RemoveBackEntry();
    }
}
